urlinfo = window.location.href;  //获取当前页面的url
console.log(urlinfo)
len = urlinfo.split("?");//获取url的长度
newsidinfo = len[1];//取出参数字符串 这里会获得类似“id=1”这样的字符串
console.log(newsidinfo);
newsids = newsidinfo.split("=");//对获得的参数字符串按照“=”进行分割
parameter1 = newsids[1];  //得到参数值 os：标识安卓还是ios，1=ios、2=安卓
console.log("获取到的参数值是" + parameter1);


function get_r1_data(line) {
    $.ajax({
        url: "/top5/" + line,
        success: function (data) {
            ec_right1_option.xAxis[0].data = data.point;
            ec_right1_option.series[0].data = data.times;
            ec_right1.setOption(ec_right1_option);
            console.log("线体急停点", data.point)
            console.log("线体急停时间", data.times)
        }
    })
}


function get_r2_data(line) {
    $.ajax({
        url: "/top5_total/" + line,
        success: function (data) {
            ec_right2_data = data;
            ec_right2_option.series[0].data = data
            ec_right2.setOption(ec_right2_option);
        }
    })
}



function get_c2_data(line) {
    $.ajax({
        url: "/output/" + line,
        success: function (data) {
            ec_center_option.series[0].data = data.data
            ec_center.setOption(ec_center_option)
        },
        error: function (xhr, type, errorThrown) {

        }
    })
}

function get_l1_data(line) {
    $.ajax({
        url: "/beat/" + line,
        success: function (data) {
            ec_left1_Option.xAxis[0].data = data.key
            ec_left1_Option.series[0].data = data.values
            ec_left1.setOption(ec_left1_Option)
            console.log("节拍名称", data.key)
            console.log("线体节拍", data.values)
        },
        error: function (xhr, type, errorThrown) {

        }
    })
}

function get_center_data(line) {
    $.ajax({
        url: "/output/" + line,
        success: function (data) {
            $(".no li").eq(0).text(data.plan);
            $(".no li").eq(1).text(data.total);
            $(".no li").eq(2).text(data.hour);
            $(".no li").eq(3).text(data.ten_min);
            console.log("今天实际产量是：", data.total)
            console.log("现在小时产量是：", data.hour)
            console.log("最近10分钟产量是：", data.ten_min)
            console.log("产量完成率是：", parseInt((data.total / data.plan) * 100))
            console.log("时间已经过去：", data.time)
            ec_center_bottom_option.series.value = data.time
            ec_center_bottom_option.series[0].data[0].value = parseInt((data.total / data.plan) * 100)
            ec_center_bottom_option.series[1].data[0].value = data.time
            ec_center_bottom.setOption(ec_center_bottom_option)
        },
        error: function (xhr, type, errorThrown) {

        }
    })
}




// 以下是左边第二个框的推移图程序

//定义变量，实例化echarts
var ec_left2 = echarts.init(document.querySelector(".line .chart"));

var ec_left2_charts = {
    unit: '台',
    names: ['计划产出', '实际产出'],
    lineX: ['8:00', '9:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00'],
    value: [
        [250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250],
        []
    ]
}

var color = ["#00f2f1", "#ed3f35"]


function get_l2_data(line) {
    $.ajax({
        url: "/beat_every/" + line,
        success: function (data) {
            ec_left2_charts.value[1] = data[1]
            ec_left2_charts.lineX = data[0]
        },
        error: function (xhr, type, errorThrown) {

        }
    })
}

function send_l2() {
    var lineY = []
    for (var i = 0; i < ec_left2_charts.names.length; i++) {
        var x = i
        if (x > color.length - 1) {
            x = color.length - 1
        }
        var data = {
            name: ec_left2_charts.names[i],
            type: 'line',
            color: color[x] + ')',
            smooth: true,
            areaStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: color[x] + ', 0.3)'
                    }, {
                        offset: 0.8,
                        color: color[x] + ', 0)'
                    }], false),
                    shadowColor: 'rgba(0, 0, 0, 0.1)',
                    shadowBlur: 10
                }
            },
            symbol: 'circle',
            symbolSize: 5,
            data: ec_left2_charts.value[i]
        }
        lineY
        lineY.push(data)
    }

    lineY[0].markLine = {
        silent: true
    }

    var ec_left2_Option = {
        // backgroundColor:'#1b2735',
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ec_left2_charts.names,
            textStyle: {
                fontSize: 12,
                color: 'rgba(255,255,255,.6)'
            },
            right: '4%'
        },
        grid: {
            top: '14%',
            left: '4%',
            right: '4%',
            bottom: '5%',
            containLabel: true
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ec_left2_charts.lineX,
            axisLabel: {
                textStyle: {
                    color: 'rgba(255,255,255,.6)'
                },
                formatter: function (params) {
                    return params.split(' ')[0]
                }
            }
        },
        yAxis: {
            name: ec_left2_charts.unit,
            type: 'value',
            axisLabel: {
                formatter: '{value}',
                textStyle: {
                    color: 'rgba(255,255,255,.6)'
                }
            },
            splitLine: {
                lineStyle: {
                    color: 'rgba(255,255,255,.6)'
                }
            },
            axisLine: {
                lineStyle: {
                    color: 'rgba(255,255,255,.6)'
                }
            }
        },
        series: lineY
    }

    ec_left2.setOption(ec_left2_Option)
    window.addEventListener("resize", function () {
        ec_left2.resize();
    });
}


// 以下是左边第三个框的商检兜圈推移图程序

// 定义变量，实例化echarts
var ec_left3 = echarts.init(document.querySelector(".line2 .chart"));

var ec_left3_charts = {
    unit: '台',
    name: '商检房兜圈数量',
    lineX: ['8:00', '9:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00'],
    value: []
}

var ec_left3_color = "#ed3f35"

function get_l3_data(line) {
    $.ajax({
        url: "/beat_every/" + line + "?point=直通",
        success: function (data) {
            ec_left3_charts.value = data[1]
            ec_left3_charts.lineX = data[0]
            console.log("直通数据是：", data)
        },
        error: function (xhr, type, errorThrown) {

        }
    })
}

function send_l3() {
    var lineY2 = []
    var data = {
        name: ec_left3_charts.name,
        type: 'line',
        color: color + ')',
        smooth: true,
        areaStyle: {
            normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: color + ', 0.3)'
                }, {
                    offset: 0.8,
                    color: color + ', 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
            }
        },
        symbol: 'circle',
        symbolSize: 5,
        data: ec_left3_charts.value
    }
    lineY2
    lineY2.push(data)
    lineY2.markLine = {
        silent: true
    }
    var ec_left3_Option = {
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ec_left3_charts.name,
            textStyle: {
                fontSize: 12,
                color: 'rgba(255,255,255,.6)'
            },
            right: '4%'
        },
        grid: {
            top: '14%',
            left: '4%',
            right: '4%',
            bottom: '5%',
            containLabel: true
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ec_left3_charts.lineX,
            axisLabel: {
                textStyle: {
                    color: 'rgba(255,255,255,.6)'
                },
                formatter: function (params) {
                    return params.split(' ')[0]
                }
            }
        },
        yAxis: {
            name: ec_left3_charts.unit,
            type: 'value',
            axisLabel: {
                formatter: '{value}',
                textStyle: {
                    color: 'rgba(255,255,255,.6)'
                }
            },
            splitLine: {
                lineStyle: {
                    color: 'rgba(255,255,255,.6)'
                }
            },
            axisLine: {
                lineStyle: {
                    color: 'rgba(255,255,255,.6)'
                }
            }
        },
        series: lineY2
    }

    ec_left3.setOption(ec_left3_Option)
    window.addEventListener("resize", function () {
        ec_left3.resize();
    });

}

// 获取右侧底部的数据
function get_right_bottom_data(line) {
    $.ajax({
        url: "/right_bottom/" + line,
        success: function (data) {
            console.log("超过2分钟的节拍累计：", data)
            // ec_right3_value = data
            ec_right3_Option.title.text = data + "分钟"
            ec_right3_Option.series[1].data[0].value = data
            ec_right3_Option.series[1].data[1].value = 100 - data
            ec_right3.setOption(ec_right3_Option)
        },
        error: function (xhr, type, errorThrown) {

        }
    })
}



// gettime()
get_l1_data(parameter1)
get_l2_data(parameter1)
get_l3_data(parameter1)
get_r1_data(parameter1)
get_r2_data(parameter1)
get_center_data(parameter1)
get_right_bottom_data(parameter1)
send_l2()
send_l3()

setInterval(get_r1_data, 10000, parameter1)
setInterval(get_r2_data, 10000, parameter1)
// setInterval(gettime, 1000)
setInterval(get_center_data, 10000, parameter1)
setInterval(get_l1_data, 10000, parameter1)
setInterval(get_l2_data, 10000, parameter1)
setInterval(send_l2, 10000)
setInterval(get_l3_data, 10000, parameter1)
setInterval(get_right_bottom_data, 10000, parameter1)
setInterval(send_l3, 10000)



